from collections import OrderedDict

from django.shortcuts import render
from django.views import View

from apps.contents.models import ContentCategory
from apps.contents.utils import get_categories
from apps.goods.models import GoodsChannel

# 首页广告

class IndexView(View):
    def get(self, request):
        """提供首页广告界面"""
        categories = get_categories()
        # 广告数据显示
        contents = {}
        # 获取广告分类
        ad_categories = ContentCategory.objects.all()
        # 便利
        for cat in ad_categories:
            # 获取数据   父对象.子类名_set.all()
            contents[cat.key] = cat.content_set.filter(status=True).order_by("sequence")
        context = {
            "categories": categories,
            "contents":contents
        }
        return render(request, 'index.html',context)

